<style>
.pull-right{
	float:right;
}
.pull-left{
	float:left;
}
th{
	text-align: left;
}
</style>
<center>
	<h1>Contract Report By Type</h1>	
</center>
<br/>
<?php
$table = new CI_Table();
$table->set_template(array(
	'table_open'=>'<table width="100%">'
));
$heading = array(
	'TYPE',
	'CONTRACT NO',
	'CustNo-LocNo',
	'NAME',
	'ADDRESS',
	'City State Zip',
	'Start date',
	'End date',
	'Billed Amount',	
);
if($model->payment){
	$heading[] = 'Payment';
}
$table->set_heading($heading); 
foreach($data as $item){
	$row = array(
		$item['type'],
		$item['contractid'],
		$item['custno'].' - '.$item['locno'],
		$item['customerName'],
		$item['add1'],
		$item['csz'],
		$item['contractstartdate'],
		$item['contractenddate'],
		array(
			'data'=>"<span class='pull-left'>Total:</span> <span class='pull-right'>".number_format($item['billedAmount'],2)."</span>",
			
		),	
		array(
			'data'=>number_format($item['paid'],2),
			'align'=>'right'
		)
	);
	
	$table->add_row($row);
	if(count($item['transactionList']) > 0){
		foreach($item['transactionList'] as $index=>$transaction){
			$table->add_row(
				array(
					'',
					'',
					'',
					'',
					'',
					'',
					'',
					'',
					array(
						'data'=>
							"<span class='pull-left'>".$transaction['type'].'-'.$transaction['invoice']."</span>".	
							"<span class='pull-right'>".number_format($transaction['amount'],2)."</span>",						
						),
					''
					)
				);
		}
	}
	$table->add_row(array(
		'data'=>'<hr/>',
		'colspan'=>10
	));
}
echo $table->generate();